package db

import (
	"fmt"
	"github.com/syndtr/goleveldb/leveldb"
	"log"
	"sync"
)

const (
	SET_VALUE  = 0
	DELETE_KEY = 1
)

type DBTYPE []byte

//db data struct
type DataMap struct {
	Key   string
	Value []byte
}

//store data in queue
type Command struct {
	Type int
	Data *DataMap
}

//db struct
type DB struct {
	DBWriter *leveldb.DB
	Wg       *sync.WaitGroup
}

//init db
func NewDB(dbPath string) *DB {
	globalDB := &DB{}
	dbfile := fmt.Sprintf("%s/data.ffdb", dbPath)
	var err error
	globalDB.DBWriter, err = leveldb.OpenFile(dbfile, nil)
	if err != nil {
		log.Fatalln("Open file failed", err)
		return nil
	}
	return globalDB
}
